package cn.woniu.ecommerceplatform.controller;

import cn.woniu.ecommerceplatform.entity.Comments;
import cn.woniu.ecommerceplatform.service.CommentsService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.ws.Response;

/**
 * @author NCQ
 * @date 2023/1/9
 */
@RestController
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    private CommentsService commentsService;
    @PostMapping("/insert")
    @PreAuthorize("hasAnyAuthority('comment:insert')")
    public ResponseResult<?> insertComments(@RequestBody Comments comments){
        return commentsService.insertComments(comments);
    }
    @PostMapping("/update")
    @PreAuthorize("hasAnyAuthority('comment:update')")
    public ResponseResult<?> updateComments(@RequestBody Comments comments){
        return commentsService.updateComments(comments);
    }
    @RequestMapping("/commentDelete")
    @PreAuthorize("hasAnyAuthority('comment:delete')")
    public ResponseResult<?> deleteComments(Integer id){
        return commentsService.deleteComments(id);
    }
    @PostMapping("/commentsDelete")
    @PreAuthorize("hasAnyAuthority('comments:delete')")
    public ResponseResult<?> deleteCommentsBranchs(@RequestBody Integer[] ids){
        return commentsService.deleteCommentsBranchs(ids);
    }
    @RequestMapping("/commentsList")
    @PreAuthorize("hasAnyAuthority('comment:list')")
    public ResponseResult<?> list(String goodCode,String customerName,String keywords){
        return commentsService.querylist(goodCode,customerName,keywords);
    }
    @RequestMapping("/changeVisiable")
    @PreAuthorize("hasAnyAuthority('comment:visible')")
    public ResponseResult<?> changeVisiable(Integer id){
        return commentsService.changeVisiable(id);
    }
    @RequestMapping("/changeTop")
    @PreAuthorize("hasAnyAuthority('comment:top')")
    public ResponseResult<?> changeTop(Integer id){
        return commentsService.changeTop(id);
    }

    @PostMapping("/commentsAdd")
    public ResponseResult<?> commentsAdd(@RequestBody Comments comments){
        return commentsService.commentsAdd(comments);
    }
}
